package grape.workflow.rest.flowable.ui.task;

import org.flowable.ui.admin.rest.client.CmmnTasksClientResource;
import org.flowable.ui.task.conf.FlowableDebuggerConfiguration;
import org.flowable.ui.task.conf.FlowableEngineConfiguration;
import org.flowable.ui.task.conf.FlowableTaskEventRegistryCondition;
import org.flowable.ui.task.properties.FlowableTaskAppProperties;
import org.flowable.ui.task.service.runtime.FlowableCommentService;
import org.flowable.ui.task.service.runtime.FlowableProcessInstanceQueryService;
import org.flowable.ui.task.service.runtime.FlowableTaskActionService;
import org.flowable.ui.task.service.runtime.FlowableTaskQueryService;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.task.TaskExecutorCustomizer;
import org.springframework.context.annotation.*;
import org.springframework.scheduling.annotation.EnableScheduling;

/**
 * Created by yangwei
 * Created at 2020/6/4 16:21
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(FlowableTaskAppProperties.class)
@ComponentScan(basePackages = {
        //"org.flowable.ui.task.conf",
        "org.flowable.ui.task.repository",
        "org.flowable.ui.task.service",
        //"org.flowable.ui.task.security",
        "org.flowable.ui.task.model.component",
        //"org.flowable.ui.common.conf",
        //"org.flowable.ui.common.repository",
        //"org.flowable.ui.common.service",
        //"org.flowable.ui.common.filter",
        //"org.flowable.ui.common.security"
},        excludeFilters = {
        // 已经自定义参见 grape.workflow.rest.flowable.ext.CustomFlowableTaskQueryService
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = FlowableTaskQueryService.class),
        // 已经自定义参见 grape.workflow.rest.flowable.ext.CustomeFlowableTaskActionService
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = FlowableTaskActionService.class),
        // 已经自定义参见 grape.workflow.rest.flowable.ext.CustomFlowableProcessInstanceQueryService
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = FlowableProcessInstanceQueryService.class),
        // 已经自定义参见  grape.workflow.rest.flowable.ext.CustomFlowableCommentService
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = FlowableCommentService .class),
})
@EnableScheduling
@Import({
        FlowableTaskEventRegistryCondition.class,
        FlowableEngineConfiguration.class,
        FlowableDebuggerConfiguration.class
})
public class TaskApplicationConfiguration {

    @Bean
    public TaskExecutorCustomizer flowableTaskTaskExecutorCustomizer() {
        return taskExecutor -> {
            // Not yet exposed via properties in Spring Boot
            taskExecutor.setAwaitTerminationSeconds(30);
            taskExecutor.setWaitForTasksToCompleteOnShutdown(true);
        };
    }

}
